{include file='public/head'}
<body>
<div class="x-body">
    <form class="layui-form" id='mainForm' method="post" action="storeUser">
        <input type="hidden" id="company_id" name="company_id" value="{$Think.get.company_id}">
        <table class="layui-table">
            <colgroup>
                <col width="50">
                <col width="500">
            </colgroup>
            <thead>
            <tr>
                <td>角色</td>
                <td>用户</td>
            </tr>
            </thead>
            <tbody>
            {volist name="role" id="vo"}
            <tr>
                <td>
                    <input type="checkbox" title="{$vo.title}" class="role_check" lay-filter="role_check"
                           lay-skin="primary">
                </td>
                <td>
                    {if isset($vo['user'])&&count($vo['user'])>0 }
                    {volist name="vo['user']" id="v"}
                    <li>
                        <input type="checkbox" value="{$v.id}" name="users[]" title="{$v.truename}" lay-skin="primary"
                               {if isset($user[$v['id']])} checked {/if}>
                    </li>
                    {/volist}
                    {/if}
                </td>
            </tr>
            {/volist}
            </tbody>
        </table>

        <div class="layui-form-item">
            <div>
                <input type="hidden" id="id" name="id" value="{$Think.get.id}">
                <button style="width: 100%" class="layui-btn" lay-submit="" lay-filter="toSubmit">提交保存</button>
            </div>
        </div>

    </form>
</div>
</body>
{include file='public/foot'}
<script type="text/javascript">
    var form = layui.form;
    //单部门全选
    form.on('checkbox(role_check)', function (data) {
        if (data.elem.checked) {
            $(this).parents("td").next("td").find("input[type='checkbox']").prop("checked", true);
        } else {
            $(this).parents("td").next("td").find("input[type='checkbox']").prop("checked", false);
        }
        form.render('checkbox');
    });
    $(document).ready(function () {
        var form = layui.form;
        var layer = layui.layer;
        var options = {
            type: 'post',           //post提交
            dataType: "json",        //json格式
            data: {},    //如果需要提交附加参数，视情况添加
            clearForm: false,        //成功提交后，清除所有表单元素的值
            resetForm: false,        //成功提交后，重置所有表单元素的值
            cache: false,
            async: false,          //同步返回
            success: function (data) {
                if (data.code == 0) {
                    layer.msg(data.msg);
                } else {
                    layer.msg(data.msg, {icon: 1, time: 500}, function () {
                        $("#reset").click();
                        x_admin_close();
                        parent.location.reload();
                    });
                }
                //服务器端返回处理逻辑
            },
            error: function (XmlHttpRequest, textStatus, errorThrown) {
                layer.msg('操作失败:服务器处理失败');
            }
        };

        // bind form using 'ajaxForm'
        $('#mainForm').ajaxForm(options).submit(function (data) {
        });
        form.render();
    });
</script>
</html>
